﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

using Webchatting.Common;
using Webchatting.Dal;


public partial class Server_RUIndex : System.Web.UI.Page
{
    public string RUId = "0";
    public string FRUId = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            logOut();
           // string LastOnlineTime;
            FormsIdentity id = (FormsIdentity)Page.User.Identity;
            OperationRU RUser = new OperationRU();
            IList<string> ilist =RUser.GetRUPortrait(id.Ticket.UserData.Split("@".ToCharArray())[0]);
            OperationFriends Ofriend = new OperationFriends();
            string getFriends = Ofriend.GetFriendsList(id.Ticket.UserData.Split("@".ToCharArray())[0]);
            Label1.Text = ilist[1] + "(" + ilist[0]+")";
            ImageButton1.ImageUrl = ilist[2];
           
            RUId = ilist[0];
            ltlText.Text = getFriends;
           // LastOnlineTime = RUser.GetOnlineInfo(id.Ticket.UserData.Split("@".ToCharArray())[0]);
          //  Response.Write(LastOnlineTime);
        }
    }
    protected void logOut()
    {
       if (Request.QueryString["action"] != null && String.Compare(Request.QueryString["action"].Trim(), "logout") == 0)
        {
            FormsIdentity id = (FormsIdentity)Page.User.Identity;
            OperationRU RUser = new OperationRU();

             int a = RUser.UpdateOnlineInfo(id.Ticket.UserData.Split("@".ToCharArray())[0]);
             if (a == 0) 
             {
                 RUser.InsertOnlineInfo(id.Ticket.UserData.Split("@".ToCharArray())[0],DateTime.Now);
             }
            FormsAuthentication.SignOut();
            Response.Redirect("/Index.aspx");
        }
    }
   
}